/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import entidad.Medicion;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author Zergio
 */
public class Graficas {
    
    private static Graficas m_instance;
    
    public synchronized static Graficas getInstance() {
        if (m_instance == null) {
            m_instance = new Graficas();
        }

        return m_instance;
    }

    private Graficas() {
    }

    public ChartPanel Graficar(ArrayList<Medicion> datos, int variable, String titulo) {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        JFreeChart chart = null;

        switch (variable) {
            case 1:
                for (Medicion m : datos) {
                    dataset.setValue(m.getTemperatura(), "Temperatura", format.format(m.getFecha()));
                }
                chart = ChartFactory.createLineChart3D(titulo, "Fecha", "°C", dataset, PlotOrientation.VERTICAL, true, true, false);
                break;
            case 2:
                for (Medicion m : datos) {
                    dataset.setValue(m.getPresionAtmosferica(), "Presion Atmosferica", format.format(m.getFecha()));
                }
                chart = ChartFactory.createLineChart3D(titulo, "Fecha", "Bar", dataset, PlotOrientation.VERTICAL, true, true, false);
                break;
            case 3:
                for (Medicion m : datos) {
                    dataset.setValue(m.getPluviosidad(), "Pluviosidad", format.format(m.getFecha()));
                }
                chart = ChartFactory.createLineChart3D(titulo, "Fecha", "Cm3", dataset, PlotOrientation.VERTICAL, true, true, false);
                break;
        }
        
        return new ChartPanel(chart);

    }
}
